package ru.gerunn.silent.message;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class MessageQueue {

	private final Queue<MessageQueueElement> queue;

	public MessageQueue() {
		queue = new ConcurrentLinkedQueue<MessageQueueElement>();
	}

	synchronized public void add(MessageQueueElement element) {
		queue.add(element);
		notifyAll();
	}

	synchronized public MessageQueueElement get() throws InterruptedException {
		while (queue.isEmpty()) {
			wait();
		}
		return queue.remove();
	}

}
